package net.yambal.android.secretary_alarm.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {
	//private Context _context;
	private static DatabaseHelper _my_instance = null;
	private static final String DB_NAME = "secretary_alarm.db";
	private static final int DB_VERSION = 2;
	private int _m_writableDatabaseCount = 0;

	public DatabaseHelper(Context context) {
		super( context.getApplicationContext(), DB_NAME, null, DB_VERSION );
		//_context = context.getApplicationContext();
	}
	
	synchronized static
	public DatabaseHelper getInstance( Context context ){
		if ( _my_instance == null ){
			_my_instance = new DatabaseHelper( context.getApplicationContext() );
		}
		return _my_instance;
	}
	
	@Override
	synchronized public SQLiteDatabase getWritableDatabase(){
		SQLiteDatabase db = super.getWritableDatabase();
		if ( db != null ){
			++ _m_writableDatabaseCount;
		}
		return db;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE IF NOT EXISTS " + AlarmsTable.TABLE + " (" +
				"_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," +
				"label TEXT NOT NULL," +
				"days TEXT NOT NULL," +
				"hour INTEGER NOT NULL," +
				"minute INTEGER NOT NULL" +
				")");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

	}
	

}
